package com.xiaoke.service.impl;

import com.xiaoke.domain.User;
import com.xiaoke.service.UserService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author xiaoke
 * @Description 用户服务实现类
 * @Date 2023/7/24 13:24
 */
@Service
public class UserServiceImpl implements UserService {


    /**
     * 根据用户名获取用户（这里只是模拟获取，你们可以从数据库里面获取）
     * @param username 用户名
     * @return 用户实体
     */
    @Override
    public User getByUserName(String username) {
        User user = null;
        try {
            user =  list()
                    .stream()
                    .filter(u -> u.getUsername().equals(username))
                    .findFirst()
                    .get();
        } catch (Exception ignored) {
        }
        return user;

    }



    private List<User> list(){
        List<User> userList = new ArrayList<>();
        userList.add(new User(1L,"admin","123456"));
        userList.add(new User(2L,"zhangsan","123456"));
        userList.add(new User(3L,"xiaoke","123456"));
        return userList;
    }

}
